﻿using System;
using System.Collections.Generic;
using System.Drawing;
using LevelEditor.Document;
using LevelEditor.Forms;

namespace LevelEditor.View
{
    public class DoUndoAddLayer : DoUndoNothing
    {
        #region Fields

        int Index;

        Layer Layer;

        Size Size;

        #endregion

        #region Constructors

        public DoUndoAddLayer(MainForm form, Layer layer):base(form)
        {
            if (layer == null)
                throw new NullReferenceException();
            Index = form.Level.Layers.Count;
            Layer = layer;
            Size = layer.Size;
        }

        #endregion

        #region Methods

        public override bool Do()
        {
            Layer AddThis = new Layer(Layer);
            MainForm.Level.Layers.Add(AddThis);
            MainForm.CurrentLayer = MainForm.Level.Layers.Count - 1;
            MainForm.RefreshControlData();
            return base.Do();
        }

        public override void Undo()
        {
            MainForm.Level.Layers.RemoveAt(Index);
            if (MainForm.CurrentLayer > MainForm.Level.Layers.Count - 1)
                MainForm.CurrentLayer = MainForm.Level.Layers.Count - 1;
            MainForm.RefreshControlData();
        }

        public override string ToString()
        {
            return "Add layer " + Index.ToString();
        }
        #endregion
    }
}
